<template>
	<view style="height: 100%">
		<form @submit.stop.prevent="formSubmit">
			<view class="inplist">
				<view class="inpbox imgInp arrow">
					<view class="dt">头像</view>
					<view class="dd addimg">
						<view v-if="userinfo.photo_state" class="inreview">{{ userinfo.photo_state }}</view>
						<view class="txImg">
							<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
								<image mode="aspectFill" v-if="userinfo.photo_audit" :src="userinfo.photo_audit" />
								<image mode="aspectFill" v-else-if="userinfo.photo" :src="userinfo.photo" />
								<image mode="aspectFill" v-else :src="imgStaticPath + '/noPhoto_100.jpg'" />
							</button>
						</view>
					</view>
				</view>

				<view class="inpbox speInp arrow">
					<view class="dt">用户名</view>
					<view class="dd" @tap="goLink" data-type="0" :data-url="userDomain + '/manage_unick.html'">
						{{ userinfo.username }}
					</view>
				</view>

				<view class="inpbox speInp">
					<view class="dt">昵称</view>
					<view class="dd">
						<view v-if="userinfo.nickname_state" class="inreview">{{ userinfo.nickname_state }}</view>
						<input v-if="userinfo.nickname_audit" type="nickname" placeholder="请输入昵称"
							:value="userinfo.nickname_audit" id="nickname" @input="inputChange" />
						<input v-else type="nickname" placeholder="请输入昵称" :value="userinfo.nickname" id="nickname"
							@input="inputChange" />
					</view>
				</view>
			</view>

			<view class="inplist">
				<!-- <view class="inpbox speInp">
            <view class="dt">QQ</view>
            <view class="dd">
                <input type="number" placeholder="请输入QQ" value="{{userinfo.qq}}" id="qq" bindinput="inputChange" />
            </view>
        </view> -->

				<view class="inpbox speInp arrow">
					<view class="dt">性别</view>
					<view class="dd">
						<picker mode="selector" :value="userinfo.sex" range-key="name" :range="sexArr" id="sex"
							@change="inputChange">
							<view class="picker">
								<text v-if="userinfo.sex">{{ sexArr[userinfo.sex]['name'] }}</text>
								<text class="placeholder" v-else>请选择性别</text>
							</view>
						</picker>
					</view>
				</view>

				<view class="inpbox speInp arrow">
					<view class="dt">生日</view>
					<view class="dd">
						<picker mode="date" :value="userinfo.birthday" id="birthday" @change="inputChange">
							<view class="picker">
								<text v-if="userinfo.birthday">{{ userinfo.birthday }}</text>
								<text class="placeholder" v-else>请选择生日</text>
							</view>
						</picker>
					</view>
				</view>

				<view class="inpbox speInp arrow">
					<view class="dt">所在地</view>
					<view class="dd" @tap="hidePop">
						<text v-if="userinfo.addrName">{{ userinfo.addrName }}</text>
						<text class="placeholder" v-else>请选择所在地</text>
					</view>
				</view>

				<view class="inpbox speInp arrow">
					<view class="dt">民族</view>
					<view class="dd">
						<picker mode="selector" :value="userinfo.nation" :range="nationArr" id="nation"
							@change="inputChange">
							<view class="picker">
								<text v-if="userinfo.nation">{{ userinfo.nation }}</text>
								<text class="placeholder" v-else>请选择民族</text>
							</view>
						</picker>
					</view>
				</view>

				<view class="inpbox speInp logintime">
					<view class="dt">注册时间</view>
					<view class="dd">
						<text v-if="userinfo.regtime">{{ userinfo.regtime }}</text>
						<text class="placeholder" v-else>未知</text>
					</view>
				</view>
			</view>

			<view class="inplist">
				<view class="submit">
					<button form-type="submit">保存</button>
				</view>
			</view>
		</form>

		<!-- 选择所在地 -->
		<view :class="'cityMask ' + (showPop ? 'show' : '')" @tap="hidePop"></view>
		<view :class="'cityScrollBox ' + (showPop ? 'show' : '')">
			<view class="h2">
				请选择
				<view class="close_pop a" @tap="hidePop">
					<image :src="masterDomain + '/static/images/close_private_phone.png?v=' + imgVersion"
						mode="aspectFit"></image>
				</view>
			</view>
			<view class="cityScroll">
				<view class="tabBox">
					<view v-if="areaArr.length > 0" :class="(currshow == ind ? 'on_chose' : '') + ' span'"
						:data-name="item.name" :data-id="item.id" :data-parentid="item.parentid" :data-index="ind"
						@tap="changeShow" v-for="(item, ind) in areaArr" :key="ind">
						<text>{{ item.name }}</text>
					</view>
					<view v-if="areaArr.length <= 0" class="span on_chose"><text>请选择</text></view>
					<view class="s" :style="'transform:translateX(' + offsetLeft + 'px)'"></view>
				</view>
				<view class="cityListBox">
					<!-- 一级 -->
					<scroll-view :class="'table-city ' + (!showFirst ? 'fn-hide' : '')" :scroll-y="true"
						:scroll-into-view="toView" :enable-back-to-top="true" :enhanced="true">
						<!-- 热门城市 -->
						<view class="hot-city" v-if="hotList && hotList.length" id="hot">
							<view class="table-tit">热门</view>
							<view class="table-list">
								<block v-for="(item, index) in hotList" :key="index">
									<text :class="currTabCityid == item.id ? 'active' : ''" :data-id="item.id"
										:data-parentid="item.parentid" :data-name="item.name" :data-lower="item.lower"
										@tap="changeCity">
										{{ item.name }}
									</text>
								</block>
							</view>
						</view>

						<block v-for="(item, index) in cityList" :key="index">
							<view :id="item.szm">
								<view class="table-tit">{{ item.szm }}</view>
								<view class="table-list">
									<block v-for="(item, index1) in item.data" :key="index1">
										<text :class="currTabCityid == item.id ? 'active' : ''" :data-id="item.id"
											:data-parentid="item.parentid" :data-name="item.name"
											:data-lower="item.lower" @tap="changeCity">
											{{ item.name }}
										</text>
									</block>
								</view>
							</view>
						</block>
					</scroll-view>

					<!-- 下级 -->
					<scroll-view :class="'ul cityList ' + (showFirst ? 'fn-hide' : '')" :scroll-top="scrollTop"
						:scroll-y="true" :enable-back-to-top="true" :enhanced="true">
						<view :class="'li ' + (item.id == currChoseCity.id ? 'active' : '')"
							v-for="(item, index) in lowerCityList" :key="index">
							<text :class="currTabCityid == item.id ? 'active' : ''" :data-id="item.id"
								:data-parentid="item.parentid" :data-name="item.name" :data-lower="item.lower"
								@tap="changeCity">
								{{ item.name }}
							</text>

							<view class="arrow" v-if="item.lower > 0"></view>
						</view>
					</scroll-view>

					<!-- 首字母筛选 -->
					<view class="letter" v-if="indexShow">{{ indexSzm }}</view>
					<view class="szm navbar jump-ul" v-if="szmList && showFirst">
						<text data-id="hot" v-if="hotList" @touchstart.stop.prevent="touchstart"
							@touchmove.stop.prevent="touchmove" @touchend.stop.prevent="touchend">热门</text>
						<block v-for="(item, index) in szmList" :key="index">
							<text :data-id="item" @touchstart.stop.prevent="touchstart"
								@touchmove.stop.prevent="touchmove" @touchend.stop.prevent="touchend">{{ item }}</text>
						</block>
					</view>
				</view>
			</view>
		</view>
		<private_tip :privateShow="privateb"></private_tip>
	</view>
</template>

<script>
	//获取应用实例
	const app = getApp();
	var _this;
	export default {
		data() {
			return {
				masterDomain: app.globalData.masterDomain,
				imgStaticPath: app.globalData.imgStaticPath,
				userDomain: app.globalData.appConfig.cfg_user_index,
				privateb: false,
				sexArr: [{
						id: 1,
						name: '男'
					},
					{
						id: 0,
						name: '女'
					}
				],

				nationArr: [
					'汉族',
					'壮族',
					'满族',
					'回族',
					'苗族',
					'维吾尔族',
					'土家族',
					'彝族',
					'蒙古族',
					'藏族',
					'布依族',
					'侗族',
					'瑶族',
					'朝鲜族',
					'白族',
					'哈尼族',
					'哈萨克族',
					'黎族',
					'傣族',
					'畲族',
					'傈僳族',
					'仡佬族',
					'东乡族',
					'高山族',
					'拉祜族',
					'水族',
					'佤族',
					'纳西族',
					'羌族',
					'土族',
					'仫佬族',
					'锡伯族',
					'柯尔克孜族',
					'达斡尔族',
					'景颇族',
					'毛南族',
					'撒拉族',
					'布朗族',
					'塔吉克族',
					'阿昌族',
					'普米族',
					'鄂温克族',
					'怒族',
					'京族',
					'基诺族',
					'德昂族',
					'保安族',
					'俄罗斯族',
					'裕固族',
					'乌孜别克族',
					'门巴族',
					'鄂伦春族',
					'独龙族',
					'塔塔尔族',
					'赫哲族',
					'珞巴族'
				],

				userinfo: {
					photo_state: '',
					photo_audit: '',
					photo: '',
					username: '',
					nickname_state: '',
					nickname_audit: '',
					nickname: '',
					sex: '',
					birthday: '',
					addrName: '',
					nation: '',
					regtime: ''
				},

				//当前用户信息
				formdata: {},

				//表单提交数据
				showPop: false,

				//是否弹窗
				areaArr: [],

				//TAB
				currshow: 0,

				//选择的TAB
				indexShow: false,

				//点击首字母筛选显示提示层
				showFirst: true,

				//是否是一级
				cityList: [],

				//一级城市数据
				hotList: [],

				//热门城市数据
				szmList: [],

				//首字母数据
				toView: 'hot',

				//正在筛选的首字母
				lowerCityList: [],

				//下级城市数据
				currTabCityid: 0,

				//当前显示区域选中的城市ID
				offsetLeft: 0,

				//TAB下边的红线
				//切换到下级滚动到顶部
				scrollTop: 0,

				imgVersion: '',
				ind: '',

				currChoseCity: {
					id: ''
				}
			};
		},
		onLoad: function(options) {
			_this = this;
			if (app.globalData.wxprivate == -1) {
				app.watchG('wxprivate', function(value) {
					_this.wxprivate=value;
					if (value) { //弹出弹窗
						_this.privateb = true;
					} else {
						_this.onload(options);
					}
				})
			} else {
				if (app.globalData.wxprivate) { //弹出弹窗
					_this.privateb = true;
				} else {
					_this.onload(options);
				}
			}
		},
		// 后退回来后，重新加载数据
		onShow() {
			this.checkLogin();
		},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			this.checkLogin();
			uni.stopPullDownRefresh();
		},
		onShareAppMessage(res) {
			let config = app.globalData.appConfig;
			return {
				title: config.share.title,
				desc: config.share.description,
				path: `/pages/index/index`,
				imageUrl: app.globalData.masterDomain + '/include/json.php?action=getSystemLogo'
			};
		},
		onShareTimeline() {
			return {
				title: config.share.title,
				imageUrl: app.globalData.masterDomain + '/include/json.php?action=getSystemLogo'
			};
		},
		methods: {
			onload(options) {
				_this.masterDomain = app.globalData.masterDomain
				_this.userDomain = app.globalData.appConfig.cfg_user_index
				var getAppConfig = setInterval(() => {
					if (_this.userDomain) {
						clearInterval(getAppConfig);
					} else {
						var userDomain = app.globalData.appConfig.cfg_user_index;
						_this.userDomain = userDomain
					}
				}, 500);
				_this.redirect = options.url;
			},
			//验证是否登录
			checkLogin() {
				_this.showPop = false
				if (app.globalData.userid) {
					var userid = app.globalData.userid;
				} else {
					var userid = uni.getStorageSync('userid');
				}
				if (userid == null || userid == '') {
					uni.showModal({
						title: '提示',
						content: '您还未登录，请登录后查看订单！',
						confirmText: '去登录',
						success(res) {
							if (res.confirm) {
								app.tologin('/pages/member/profile/index');
							} else {
								var referpage = getCurrentPages()[0].__displayReporter.showReferpagepath; //上个页面
								//前面有页面时
								if (referpage) {
									uni.navigateBack({
										delta: 1
									});
								} else {
									uni.redirectTo({
										url: '/pages/index/index'
									});
								}
							}
						}
					});
					return;
				} else {
					this.loadData();
				}
			},

			//更新头像
			onChooseAvatar(e) {
				const {
					avatarUrl
				} = e.detail;
				uni.showLoading({
					title: '上传中...',
					mask: true,
					success: () => {
						uni.uploadFile({
							filePath: avatarUrl,
							name: 'Filedata',
							url: app.globalData.masterDomain + '/include/upload.inc.php',
							formData: {
								mod: 'siteConfig',
								type: 'photo'
							},
							success: (res) => {
								uni.hideLoading();
								let detail = JSON.parse(res.data);
								if (detail.state != 'SUCCESS') {
									// uni.showToast({
									// 	title: detail.state,
									// 	icon: 'none',
									// 	duration: 2000
									// });
									uni.showModal({
										title:'温馨提示',
										content:detail.state,
										showCancel:false,
									})
								} else {
									var url = detail.url;
									var turl = detail.turl;
									var userinfo = _this.userinfo;
									uni.showLoading({
										title: '保存中...'
									});
									var dataPrarm = '&service=member&action=updateProfilePhoto';
									var urlData = app.encodeUrl(dataPrarm);
									_this.$ajax.post({
										url: 'include/ajax.php?photo=' + url + urlData,
										header: 'application/x-www-form-urlencoded',
									}).then(res => {
										uni.hideLoading();
										var data = res.data;
										var photo_audit = data.photo_audit;
										var photo_state = data.photo_state;
										if (data.state == 100) {
											uni.showToast({
												title: '保存成功',
												icon: 'success',
												duration: 2000
											});

											//更新页面数据
											userinfo.photo = turl;

											//需要审核
											if (photo_audit && photo_state) {
												userinfo.photo_audit = photo_audit;
												userinfo.photo_state = photo_state;
											} else {
												userinfo.photo_audit = '';
												userinfo.photo_state = '';
											}
											_this.userinfo = userinfo
										} else {
											// uni.showToast({
											// 	title: data.info,
											// 	icon: 'none',
											// 	duration: 2000
											// });
											uni.showModal({
												title:'温馨提示',
												content: data.info,
												showCancel:false,
											})
										}
									})
								}
							},
							fail: () => {
								uni.hideLoading({
									success: () => {
										uni.showToast({
											title: '上传失败',
											icon: 'error',
											duration: 2000
										});
									}
								});
							}
						});
					}
				});
			},

			//更新表单
			inputChange(e) {
				var target = e.target;
				var detail = e.detail;
				var inpid = target.id;
				var value = detail.value;
				var userinfo = _this.userinfo;

				//昵称
				if (inpid == 'nickname') {
					userinfo['nickname'] = value;
					userinfo['nickname_audit'] = '';
					userinfo['nickname_state'] = '';
				}

				//QQ
				if (inpid == 'qq') {
					value = value.replace(/\D+/gi, '');
					userinfo['qq'] = value;
				}

				//性别
				if (inpid == 'sex') {
					userinfo['sex'] = value;
					value = _this.sexArr[value]['id'];
				}

				//生日
				if (inpid == 'birthday') {
					userinfo['birthday'] = value;
				}

				//民族
				if (inpid == 'nation') {
					value = _this.nationArr[value];
					userinfo['nation'] = value;
				}

				//更新表单数据
				_this.formdata[inpid] = value;
				_this.formdata = _this.formdata
				_this.userinfo = userinfo
			},

			formSubmit(e) {
				var formdata = _this.formdata;
				var data = [];
				data.push('rsaEncrypt=1');
				data.push('nickname=' + app.rsaEncrypt(formdata.nickname));
				// data.push("qq=" + app.rsaEncrypt(formdata.qq));  //小程序涉嫌在非合理场景下收集、存储用户密码或个人敏感信息，包括但不限于微信帐号、QQ号码等，违反《微信小程序平台运营规范》及相关规则，请移除违规后再重新提交代码审核。
				data.push('sex=' + app.rsaEncrypt(formdata.sex));
				data.push('birthday=' + app.rsaEncrypt(formdata.birthday));
				data.push('addr=' + app.rsaEncrypt(formdata.addr));
				data.push('nation=' + app.rsaEncrypt(formdata.nation));
				uni.showLoading({
					title: '保存中...'
				});
				var dataPrarm = 'service=member&action=updateProfile';
				var urlData = app.encodeUrl(dataPrarm);
				_this.$ajax.post({
					url: 'include/ajax.php?' + urlData,
					data: data.join('&'),
					header: 'application/x-www-form-urlencoded'
				}).then(res => {
					uni.hideLoading();
					var data = res.data;
					if (data.state == 100) {
						uni.showToast({
							title: '保存成功',
							icon: 'success',
							duration: 2000,
							success: function() {
								if (_this.redirect != '' && _this.redirect != undefined) {
									uni.navigateBack({
										delta: 1,
										success: function(e) {
											//后退到上一页并重新打开登录前的页面
											uni.redirectTo({
												url: '/pages/redirect/index?url=' +
													encodeURIComponent(_this.redirect)
											});
										},
										fail: function() {
											//没有上一页，在当前页直接打开
											uni.redirectTo({
												url: '/pages/redirect/index?url=' +
													encodeURIComponent(_this.redirect)
											});
										}
									});
								}
							}
						});
					} else {
						// uni.showToast({
						// 	title: data.info,
						// 	icon: 'none',
						// 	duration: 2000
						// });
						uni.showModal({
							title:'温馨提示',
							content: data.info,
							showCancel:false,
						})
					}
				})
			},

			//加载数据
			loadData() {
				uni.showLoading({
					title: '加载中...'
				});

				//获取用户基本信息
				var userid = app.globalData.userid;
				var dataPrarm = 'service=member&action=detail&id=' + userid;
				var urlData = app.encodeUrl(dataPrarm);
				_this.$ajax.post({
					url: 'include/ajax.php?' + urlData,
				}).then(res => {
					uni.hideLoading();
					var data = res.data;
					if (data.state == 100) {
						var info = data.info;
						info['birthday'] = info['birthday'] ? app.transTimes(info['birthday'],
							2) : '';
						info['addrName'] = info['addrName'].replace(/\>/g, '');
						var formdata = {};
						formdata['nickname'] = info['nickname'];
						formdata['qq'] = info['qq'];
						formdata['sex'] = data.info.sex;
						formdata['birthday'] = info['birthday'];
						formdata['addr'] = info['addrid'];
						formdata['nation'] = info['nation'];

						// 性别需要转一下
						info['sex'] = info['sex'] == '1' ? '0' : '1';
						_this.userinfo = info
						_this.formdata = formdata
					} else {
						// uni.showToast({
						// 	title: data.info,
						// 	icon: 'none',
						// 	duration: 2000
						// });
						uni.showModal({
							title:'温馨提示',
							content: data.info,
							showCancel:false,
						})
					}
				})
			},

			//显示隐藏选择区域
			hidePop() {
				var showPop = !_this.showPop;
				if (showPop && _this.cityList.length == 0) {
					_this.getCityList();
				}
				_this.showPop = showPop
			},

			//切换TAB选中滑块
			changTabOffset() {
				var query = uni.createSelectorQuery();
				query
					.select('.on_chose')
					.boundingClientRect(function(rect) {
						var left = rect.left + rect.width / 2;
						_this.offsetLeft = left
					})
					.exec();
			},

			//切换TAB
			changeShow(e) {
				var target = e.currentTarget;
				var dataset = target.dataset;
				var index = parseInt(dataset.index);
				var id = dataset.id;
				var parentid = dataset.parentid;
				var areaArr = _this.areaArr;
				var currTabCityid = areaArr[index]['id'];
				if (index == 0) {
					_this.showFirst = true
					_this.currshow = 0
					_this.currTabCityid = currTabCityid
				} else {
					_this.showFirst = false
					_this.currshow = index
					_this.currTabCityid = currTabCityid
					_this.getCityList(parentid);
				}
				_this.changTabOffset();
			},

			//点击选择城市
			changeCity(e) {
				var target = e.target;
				var dataset = target.dataset;
				var id = dataset.id;
				var parentid = dataset.parentid;
				var name = dataset.name;
				var lower = dataset.lower;
				var areaArr = _this.areaArr;

				//有下级数据时
				if (lower != '' && lower > 0) {
					var currshow = _this.currshow;

					//先删除下级
					areaArr.splice(currshow);
					if (areaArr.length > 0) {
						if (areaArr[areaArr.length - 1].id == 0) {
							areaArr.splice(areaArr.length - 1);
						}
					}
					areaArr.push({
						parentid: parentid,
						id: id,
						name: name
					}, {
						parentid: id,
						id: 0,
						name: '请选择'
					});
					_this.getCityList(id);
					_this.showFirst = false
					_this.areaArr = areaArr
					_this.currshow = areaArr.length - 1
					_this.scrollTop = 0
					_this.lowerCityList = []
				}
				//最后一级
				else {
					var addrName = [];
					areaArr[areaArr.length - 1] = {
						parentid: parentid,
						id: id,
						name: name
					};

					//提取区域名称
					areaArr.forEach((element) => {
						addrName.push(element.name);
					});

					//更新页面和表单数据
					_this.userinfo.addrName = addrName.join(' ');
					_this.formdata.addr = id;
					_this.areaArr = areaArr
					_this.currshow = areaArr.length - 1
					_this.currTabCityid = id
					_this.scrollTop = 0
					_this.userinfo = _this.userinfo
					_this.formdata = _this.formdata
					_this.showPop = false
				}
				_this.changTabOffset();
			},

			//获取区域数据
			getCityList(id = 0) {
				_this.changTabOffset();
				uni.showLoading({
					title: '加载中...'
				});
				var sortBy = function(prop) {
					return function(obj1, obj2) {
						var val1 = obj1[prop];
						var val2 = obj2[prop];
						if (!isNaN(Number(val1)) && !isNaN(Number(val2))) {
							val1 = Number(val1);
							val2 = Number(val2);
						}
						if (val1 < val2) {
							return -1;
						} else if (val1 > val2) {
							return 1;
						} else {
							return 0;
						}
					};
				};
				var dataPrarm = 'service=siteConfig&action=addr&type=' + id;
				var urlData = app.encodeUrl(dataPrarm);
				_this.$ajax.post({
					url: 'include/ajax.php?' + urlData,
				}).then(res => {
					uni.hideLoading();
					var data = res.data;
					if (data.state == 100) {
						var list = data.info;
						var cityArr = new Array();
						var cityList = [];
						var szmList = [];
						var hotList = []; //一级
						if (id == 0) {
							for (var i = 0; i < list.length; i++) {
								var pinyin = list[i].pinyin.substr(0, 1);
								if (cityArr[pinyin] == undefined) {
									cityArr[pinyin] = [];
								}
								cityArr[pinyin].push(list[i]);
							}

							//首字母
							var szmArr = [];
							for (var key in cityArr) {
								var szm = key;
								// 右侧字母数组
								szmArr.push(key);
							}

							// 右侧字母填充
							szmArr.sort();
							szmList = szmArr;
							for (var i = 0; i < szmArr.length; i++) {
								cityArr[szmArr[i]].sort(sortBy('id'));
								var cityListData = [];
								for (var j = 0; j < cityArr[szmArr[i]].length; j++) {
									cityListData.push({
										name: cityArr[szmArr[i]][j].typename,
										id: cityArr[szmArr[i]][j].id,
										parentid: cityArr[szmArr[i]][j].parentid,
										lower: cityArr[szmArr[i]][j].lower ? cityArr[szmArr[i]][j]
											.lower : 0
									});
									if (cityArr[szmArr[i]][j].hot == 1) {
										hotList.push({
											name: cityArr[szmArr[i]][j].typename,
											id: cityArr[szmArr[i]][j].id,
											parentid: cityArr[szmArr[i]][j].parentid,
											lower: cityArr[szmArr[i]][j].lower ? cityArr[szmArr[i]]
												[j].lower : 0
										});
									}
								}
								cityList[szmArr[i]] = cityListData;
							}
							var cityListData = [];
							for (var n in cityList) {
								cityListData.push({
									szm: n,
									data: cityList[n]
								});
							}
							_this.cityList = cityListData
							_this.szmList = szmList
							_this.hotList = hotList
						}
						//下级
						else {
							var cityListData = [];
							for (var j = 0; j < list.length; j++) {
								cityListData.push({
									name: list[j].typename,
									id: list[j].id,
									parentid: list[j].parentid,
									lower: list[j].lower ? list[j].lower : 0
								});
							}
							_this.lowerCityList = cityListData
						}
					} else {
						// uni.showToast({
						// 	title: data.info,
						// 	icon: 'none',
						// 	duration: 2000
						// });
						uni.showModal({
							title:'温馨提示',
							content: data.info,
							showCancel:false,
						})
					}
				})
			},

			//首字母快速定位
			touchstart(e) {
				uni.vibrateShort();
				_this.toView = e.target.dataset.id.toLowerCase()
				_this.indexy = e.touches[0].pageY
				_this.indexShow = true
				_this.indexSzm = e.target.dataset.id == 'hot' ? '热门' : e.target.dataset.id
			},

			//首字母快速定位
			touchmove(e) {
				var y = this.getArrIndex(e.target.dataset.id);
				var indexY = e.touches[0].pageY;
				if (this.getArrEnglish(Math.round((indexY - this.indexy) / 15), y)) {
					var szm = this.getArrEnglish(Math.round((indexY - this.indexy) / 15), y);
					_this.toView = szm == '热门' ? 'hot' : szm.toLowerCase()
					_this.indexSzm = szm
				}
			},

			//首字线快速定位
			touchend(e) {
				_this.indexShow = false
			},

			//获取touchstart字母数组角标
			getArrIndex(english) {
				var szmList = this.szmList;
				for (var x = 0; x < szmList.length; x++) {
					if (english == szmList[x]) {
						return x;
					}
				}
			},

			//num 移动了多少位 index 当前字母,返回当前触摸位置节点的字母
			getArrEnglish(num, index) {
				var szmList = this.szmList;
				var english = szmList[index + num];
				if (!(1 > num + index > 26)) {
					return english == undefined ? '热门' : english;
				} else {
					return AAA;
				}
			},

			// 跳转链接
			goLink(e) {
				var currentTarget = e.currentTarget;
				var url = currentTarget.dataset.url;
				if (!url) {
					return false;
				}

				//原生页面
				if (currentTarget.dataset.type == 1) {
					url = url.replace('miniprogram://', '/');
					uni.navigateTo({
						url: app.addUrlParam(url)
					});
					//小程序类型
				} else if (currentTarget.dataset.type == 2) {
					var ahref = url.replace('wxMiniprogram://', '');
					var miniId = ahref.split('?/')[0];
					var //小程序原始id
						path = ahref.split('?/')[1]; //跳转的路径
					var _ghId = miniId.split('/')[0];
					var _appid = miniId.split('/')[1];
					if (path) {
						var _path = '/' + path;
					} else {
						var _path = '';
					}
					uni.navigateToMiniProgram({
						appId: _appid,
						path: _path,
						success(res) {
							// wx.navigateBack();
						},
						fail(res) {
							uni.showToast({
								title: res,
								icon: 'success',
								duration: 2000
							});
						}
					});

					//H5链接
				} else {
					if (url.indexOf('work.weixin.qq.com/kfid') > -1) {
						//小程序跳转客服
						var link = url.split('?id=')[0];
						var //客服链接
							id = url.split('?id=')[1]; //企业ID
						var path = '/pages/openkf/openkf?url=' + encodeURIComponent(link) + '&id=' + id;
						if (link && id) {
							uni.openCustomerServiceChat({
								extInfo: {
									url: link
								},
								corpId: id,
								success(res) {
									console.log(res);
								}
							});
						} else {
							uni.navigateTo({
								url: '/pages/redirect/index?url=' + encodeURIComponent(app.addUrlParam(
									url))
							});
						}
					} else {
						uni.navigateTo({
							url: '/pages/redirect/index?url=' + encodeURIComponent(app.addUrlParam(url))
						});
					}
				}
			}
		}
	};
</script>
<style>
	@import './index.css';
</style>